/*
 *  Copyright (C) 2011 Matt Van Der Westhuizen <mattpwest@gmail.com>
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.chaoticengine.cgll.entity.component.move;

import java.util.HashMap;
import org.chaoticengine.cgll.CGLLGameState;
import org.chaoticengine.cgll.camera.Camera;
import org.chaoticengine.cgll.entity.component.ActiveComponent;
import org.chaoticengine.cgll.input.Command;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.geom.Vector2f;

/**
 * This class provides an entity with a range of ways to control the
 * camera, including:
 *   -Keyboard arrow key scrolling.
 *   -Mouse screen edge scrolling.
 *   -Mouse right-click-and-drag scrolling.
 *
 * @author Matt Van Der Westhuizen <mattpwest@gmail.com>
 */
public class CameraFollowComponent extends ActiveComponent {
    private Camera camera = null;

    public CameraFollowComponent() {
        super();

        // Add camera motion commands
        commands = new HashMap<String, Command>();
    }

    @Override
    public void onSetOwner() {
        super.onSetOwner();
    }

    @Override
    public void update(GameContainer gc, StateBasedGame sb, int delta) {
        // Follow the owning entity if we're not doing so already
        if (camera == null) {
            CGLLGameState state = (CGLLGameState) sb.getCurrentState();
            camera = state.getCamera();
            camera.follow(getOwner());
        }

        super.update(gc, sb, delta);
    }
}
